home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / S / Smaller Installer 1.0.2 / Hook Proc Examples / DemoHook / DemoHook.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-17  |  7.7 KB  |  238 lines  |  [TEXT/KAHL]

  1. /******************************************************************************
  2. *                                                                                                        *
  3. *                                         Smaller Installerâ„¢                                        *
  4. *                                                                                                        *
  5. *                                        Â© 1992 Bill Goodman                                        *
  6. *                                        All Rights Reserved                                        *
  7. *                                                                                                        *
  8. *******************************************************************************
  9.  
  10. Demonstration Hook Example
  11.  
  12. This is an example of an installer hook procedure. It displays an alert each
  13. time the hook procedure is called.
  14.  
  15. To use this hook procedure, you must compile this code and create a code
  16. resource with type 'SICR' and an ID of 500.  This resource should be
  17. non-preloaded, nonpurgeable, unlocked, unprotected and non-sysheap.  Copy this
  18. resource and the ALRT/DITL resources from the "DemoHook.ALRT.rsrc" file to your
  19. installer's resource file.
  20.  
  21. ******************************************************************************/
  22.  
  23. #include <SetUpA4.h>
  24. #include "SIHookProc.h"
  25.  
  26.  
  27. /******************************************************************************
  28.     Module Internal Function Prototypes
  29. ******************************************************************************/
  30. void SetTargetVolFunction(void);
  31. void BeginInstallFunction(void);
  32. void EndInstallFunction(void);
  33. void BuildGroupString(unsigned char *groupPStr);
  34.  
  35.  
  36. /******************************************************************************
  37.     Constant Declarations
  38. ******************************************************************************/
  39. /* Alert Definitions */
  40. #define setTgtAlrt            500    /* Resource ID of SetTargetVol alert */
  41. #define beginAlrt                501    /* Resource ID of BeginInstall alert */
  42. #define cancel_beginAlrt    2        /* Item number of CANCEL button */
  43. #define endAlrt                502    /* Resource ID of EndInstall alert */
  44. #define cancel_endAlrt        2        /* Item number of CANCEL button */
  45.  
  46.  
  47. /******************************************************************************
  48.     Module Variables Declarations
  49. ******************************************************************************/
  50. SIHookParmBlk *parms;                    /* Global pointer to parameter block */
  51. unsigned char emptyPStr[] = "\p";    /* Empty Pascal string */
  52.  
  53.  
  54. /*****************************************************************************/
  55. pascal void main(
  56.         SIHookParmBlk *parmBlk    /* Pointer to parameter block */
  57.         )
  58. /******************************************************************************
  59.     This is the main entry point for the installer hook procedure.
  60. ******************************************************************************/
  61. {
  62. RememberA0();    /* This is necessary to access any global variables */
  63. SetUpA4();
  64. parms = parmBlk;
  65.  
  66. switch (parms->function)
  67.     {
  68.     case siHookSetTargetVol:
  69.         SetTargetVolFunction();
  70.         break;
  71.  
  72.     case siHookBeginInstall:
  73.         BeginInstallFunction();
  74.         break;
  75.  
  76.     case siHookEndInstall:
  77.         EndInstallFunction();
  78.         break;
  79.     }
  80. RestoreA4();
  81. }
  82.  
  83.  
  84. /*****************************************************************************/
  85. void SetTargetVolFunction(void)
  86. /******************************************************************************
  87.     Input parameters:
  88.         "targetVRefNum" - Volume reference number of target volume
  89.         "groupAPFlags", "groupQUSel", "groupVZSel" - Groups currently selected
  90.                                                                     for installation
  91.     Returns:
  92.         "groupAPFlags", "groupQUSel", "groupVZSel" - New installation groups
  93.  
  94.     This function is called at startup and whenever the target volume is
  95.     changed.
  96. ******************************************************************************/
  97. {
  98. HParamBlockRec pb;
  99. Str255 volumePStr;
  100. Str255 selectedGroupsPStr;
  101. OSErr error;
  102.  
  103. BuildGroupString(selectedGroupsPStr);
  104.  
  105. /* Get volume name */
  106. pb.volumeParam.ioVRefNum = parms->targetVRefNum;
  107. pb.volumeParam.ioNamePtr = volumePStr;
  108. pb.volumeParam.ioVolIndex = 0;
  109. error = PBHGetVInfoSync(&pb);
  110. if (error == noErr)
  111.     {    /* Display the target volume name and the selected groups in an alert */
  112.     ParamText(volumePStr, selectedGroupsPStr, emptyPStr, emptyPStr);
  113.     NoteAlert(setTgtAlrt, NULL);
  114.     }
  115. }
  116.  
  117.  
  118. /*****************************************************************************/
  119. void BeginInstallFunction(void)
  120. /******************************************************************************
  121.     Input parameters:
  122.         "targetVRefNum" - Volume reference number of target volume
  123.         "groupAPFlags", "groupQUSel", "groupVZSel" - Groups currently selected
  124.                                                                     for installation
  125.     Returns:
  126.         "result" - Hook result code
  127.  
  128.     This function is called when the install button is clicked to begin
  129.     installing files.
  130. ******************************************************************************/
  131. {
  132. HParamBlockRec pb;
  133. Str255 volumePStr;
  134. Str255 selectedGroupsPStr;
  135. OSErr error;
  136.  
  137. BuildGroupString(selectedGroupsPStr);
  138.  
  139. /* Get volume name */
  140. pb.volumeParam.ioVRefNum = parms->targetVRefNum;
  141. pb.volumeParam.ioNamePtr = volumePStr;
  142. pb.volumeParam.ioVolIndex = 0;
  143. error = PBHGetVInfoSync(&pb);
  144. if (error != noErr)
  145.     goto Error;
  146.  
  147. /* Display the target volume name and the selected groups in an alert */
  148. ParamText(volumePStr, selectedGroupsPStr, emptyPStr, emptyPStr);
  149. if (NoteAlert(beginAlrt, NULL) == cancel_beginAlrt)
  150.     goto Error;    /* Return error to indicate user cancelled operation */
  151.  
  152. return;    /* Note that it is not necessary to set the result if no error */
  153.  
  154. /* Error occurred or user cancelled operation */
  155. Error:
  156. parms->result = siHookAbort;
  157. }
  158.  
  159.  
  160. /*****************************************************************************/
  161. void EndInstallFunction(void)
  162. /******************************************************************************
  163.     Input parameters:
  164.         "targetVRefNum" - Volume reference number of target volume
  165.         "groupAPFlags", "groupQUSel", "groupVZSel" - Groups currently selected
  166.                                                                     for installation
  167.         "completionSts" - Indicates any errors which occurred during installation
  168.     Returns:
  169.         "result" - Hook result code
  170.  
  171.     This function is called at the end of the installation process.
  172. ******************************************************************************/
  173. {
  174. HParamBlockRec pb;
  175. Str255 volumePStr;
  176. Str255 selectedGroupsPStr;
  177. StringPtr statusPtr;
  178. OSErr error;
  179.  
  180. if (parms->completionSts == siHookComplete)
  181.     statusPtr = "\pInstallation complete. All files installed.";
  182. else if (parms->completionSts == siHookFileSkipped)
  183.     statusPtr = "\pInstallation complete. Some files were skipped.";
  184. else
  185.     statusPtr = "\pInstallation was aborted.";
  186.  
  187. BuildGroupString(selectedGroupsPStr);
  188.  
  189. /* Get volume name */
  190. pb.volumeParam.ioVRefNum = parms->targetVRefNum;
  191. pb.volumeParam.ioNamePtr = volumePStr;
  192. pb.volumeParam.ioVolIndex = 0;
  193. error = PBHGetVInfoSync(&pb);
  194. if (error != noErr)
  195.     goto Error;
  196.  
  197. /* Display the target volume name, the selected groups and the completion */
  198. /* status in an alert */
  199. ParamText(volumePStr, selectedGroupsPStr, statusPtr, emptyPStr);
  200. if (NoteAlert(endAlrt, NULL) == cancel_endAlrt)
  201.     goto Error;    /* Return error to indicate user cancelled operation */
  202.  
  203. return;    /* Note that it is not necessary to set the result if no error */
  204.  
  205. /* Error occurred or user cancelled operation */
  206. Error:
  207. parms->result = siHookAbort;
  208. }
  209.  
  210.  
  211. /*****************************************************************************/
  212. void BuildGroupString(
  213.         unsigned char *groupPStr    /* Returned group string */
  214.         )
  215. /******************************************************************************
  216.     Build a list of selected groups and return in the specified string.
  217. ******************************************************************************/
  218. {
  219. short index;
  220. short count;
  221.  
  222. index = 1;
  223. for (count = 0; count < 16; count++)
  224.     {
  225.     if (parms->groupAPFlags & (0x0001 << count))
  226.         {    /* Group is selected - add to list */
  227.         groupPStr[index++] = 'A' + count;
  228.         groupPStr[index++] = ',';
  229.         groupPStr[index++] = ' ';
  230.         }
  231.     }
  232. groupPStr[index++] = 'Q' + parms->groupQUSel;
  233. groupPStr[index++] = ',';
  234. groupPStr[index++] = ' ';
  235. groupPStr[index] = 'V' + parms->groupVZSel;
  236. groupPStr[0] = index;
  237. }
  238.